package yxm.zyf.love.jdk11;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * packageName: Testjdk11
 * var jdk10新增的关键字
 */
public class Testjdk12 {

    static class ThreadSafeSample {
        public int sharedState;

        public synchronized void nonSafeAction() {
            while (sharedState < 100000) {
                int former = sharedState++;
                int latter = sharedState;
                if (former != latter - 1) {
                    System.out.printf("Observed data race, former is " +
                            former + ", " + "latter is " + latter);
                }
            }
        }

        public static void main(String[] args) throws InterruptedException {
            ThreadSafeSample sample = new ThreadSafeSample();
            Thread threadA = new Thread() {
                @Override
                public void run() {
                    sample.nonSafeAction();
                }
            };
            Thread threadB = new Thread() {
                @Override
                public void run() {
                    sample.nonSafeAction();
                }
            };
            threadA.start();
            threadB.start();
            threadA.join();
            threadB.join();
        }
    }
}
